import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/components/Login'
import Home from '@/components/Home'
import Welcome from '@/components/Welcome'
import Manager from '@/components/Manager'
import Permission from '@/components/Permission'
import Order from '@/components/Order'
import Sysrole from '../components/Sysrole'
import Permisssion from '../components/Permission'
import Hospital from "@/components/Hospital";
import Goods from '@/components/goods/Goods'
import Brand from '@/components/goods/Brand'
import User from '@/components/User'
import Dynamic from '@/components/Dynamic'
import IntelligencePlanet from '@/components/IntelligencePlanet'





Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/login"
  },
  {
    path: '/login',
    name:'Login',
    component:Login,
  },
  {
    path:'/home',
    component:Home,
    redirect:'/welcome',
    children:[{
      path:'/welcome',
      component:Welcome,
    },{
        path:'/manager',
        component:Manager,

    },
        {
            path:'/permission',
            component:Permission
        },{
            path:'/order',
            component:Order
        }
    ]
  },
    {
        path: '/',
        redirect: "/login"
    },
    {
        path: '/login',
        name: 'Login',
        component: Login,
    },
    {
        path: '/home',
        component: Home,
        redirect: '/welcome',
        children: [
            {
                path: '/welcome',
                component: Welcome,
            },
            {
                path:'/sysrole',
                name:Sysrole,
                component:Sysrole
            },
            {
                path:"/permission",
                name:Permisssion,
                component:Permisssion
            },
            {
                path:'/goods',
                name:Goods,
                component:Goods,
            },
            {
                path:'/brand',
                name:Brand,
                component:Brand
            },
            {
                path:"/hospital",
                name:Hospital,
                component:Hospital
            },{
                path:"/user",
                name:User,
                component:User
            },{
                path:"/dynamic",
                name:Dynamic,
                component:Dynamic
            },{
                path:"/intelligencePlanet",
                name:IntelligencePlanet,
                component:IntelligencePlanet,
            }


    ]
  },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})


router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        return next()
    }
    /*const userCode = sessionStorage.getItem("userCode");
    if(!userCode){
      return next('/login')
    }*/
    next();
})

export default router
